<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>线上买卖通首页</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <!-- 标签页图标 -->
    <!--<link rel="shortcut icon"  href="/images/icon/favicon.ico" type="image/x-icon"/>-->
    <link rel="icon" href="/images/icon/menu_title_1.jpg" />
    <link rel="shortcut icon" href="/images/icon/menu_title_1.jpg" />
    <link rel="bookmark" href="/images/icon/menu_title_1.jpg" />
</head>
<script src="/js/layui/layui.all.js" charset="utf-8"></script>
<script src="/js/jquery.js" charset="utf-8"></script>
<script src="/js/localStorage.js" charset="utf-8"></script>
<body>
<ul style="width: 100%;" class="layui-nav" lay-filter="">
    <li id="login" class="layui-nav-item"><a href="/v1.0/login">登录</a></li>
    <li class="layui-nav-item layui-this"><!-- layui-this -->
        <a href="javascript:;">关于本站</a>
        <dl class="layui-nav-child"> <!-- 二级菜单 -->
            <dd><a href="#">免费版本</a></dd>
            <dd><a href="/v1.0/register" target="_blank">无法注册请点这里</a></dd>
            <dd><a href="#">更好的ui建议请联系QQ：1084986263</a></dd>
        </dl>
    </li>
    <li class="layui-nav-item">
        <a href="javascript:;">动态化规则选项</a>
        <dl class="layui-nav-child"> <!-- 二级菜单 -->
            <dd><a href="#" onclick="addField()">添加采集字段</a></dd>
            <dd><a href="#" onclick="addCollectRule()">添加采集规则</a></dd>
            <dd><a href="#">敬请等待...</a></dd>
        </dl>
    </li>
    <li class="layui-nav-item">
        <a href="/v1.0/taobao_list" target="_blank">买家：进入淘宝站</a>
    </li>
    <li class="layui-nav-item">
        <a href="/v1.0/1688_list" target="_blank">店家：进入1688站</a>
    </li>
    <li class="layui-nav-item">
        <a href="https://www.taobao.com/" target="_blank">淘宝采购</a>
    </li>
    <li class="layui-nav-item">
        <a href="https://detail.1688.com" target="_blank">1688采购</a>
    </li>
    <li class="layui-nav-item">
        <a href="/v1.0/index" target="_blank">使用手册</a>
    </li>
</ul>

<div class="">
    <br/><br/>
    <!-- 淘宝-->
    <div style="margin-bottom: 10px;">淘宝商品链接：</div>
    <input type="text" id="taobao_url"
           value="https://item.taobao.com/item.htm?spm=a219r.lm874.14.240.b7a65b62BbegX1&id=566130329766&ns=1&abbucket=3"
           name="title" required
           lay-verify="required"
           placeholder="请输入淘宝&天猫网址" autocomplete="off" class="layui-input">
    <button class="layui-btn layui-btn-radius layui-btn-primary" onclick="taobao_collect()">生成<span
            style="color: #F74C31">淘宝&天猫</span>商品信息
    </button>
    <br/><br/>
    <!-- 1688-->
    <div style="margin-bottom: 10px;">1688商品链接：</div>
    <input type="text" id="url" value="https://detail.1688.com/offer/564521392898.html" name="title" required
           lay-verify="required"
           placeholder="请输入1688网址" autocomplete="off" class="layui-input">
    <button class="layui-btn layui-btn-radius layui-btn-primary" onclick="collect()">生成<span
            style="color: #F74C31">1688</span>商品信息
    </button>


</div>

<div id="menu" hidden="hidden">
    <button class="layui-btn">生成1688同款</button>
    <button class="layui-btn">生成淘宝&天猫同款</button>
    <button class="layui-btn layui-btn-normal">查看1688同款</button>
    <button class="layui-btn layui-btn-normal">查看淘宝&天猫同款</button>
    <button class="layui-btn layui-btn-danger">删除</button>
</div>

<br/><br/><br/>
<!-- 轮播-->
<div class="layui-carousel" id="test1">
    <div carousel-item>
        <div style="background-color: #009688;">
            <h1 style="text-align:center;color:#ffffff;margin-top: 40px;">我是店家</h1>
            <br/>
            <a href="/v1.0/producerDocument" target="_blank"><h2 style="text-align:center;color:#ffffff">点我进入教程</h2></a>
        </div>
        <div style="background-color: #5FB878">
            <h1 style="margin: auto auto;text-align:center;color:#ffffff;margin-top: 40px;">我是买家</h1>
            <br/>
            <a href="/v1.0/consumerDocument" target="_blank"><h2
                    style="margin: auto auto;text-align:center;color:#ffffff">点我进入教程</h2></a>
        </div>
        <div style="background-color: #666666;">
            <h1 style="text-align:center;color:#ffffff;margin-top: 40px;">如有疑问，请联系我们：</h1>
            <br/>
            <h2 style="text-align:center;color:#ffffff">Teddy's phone number: 18110225751 || 17826821344</h2>
            <br/>
            <h2 style="text-align:center;color:#ffffff">Teddy's QQ number: 1084986263</h2>
            <br/>
            <h2 style="text-align:center;color:#ffffff">Teddy's WeChat number: 18110225751</h2>
        </div>
        <div style="background-color: #009E94">
            <h1 style="text-align:center;color:#ffffff;margin-top: 40px;">内测阶段，如有好的建议，请至邮箱：</h1>
            <br/>
            <br/>
            <br/>
            <h2 style="text-align:center;color:#ffffff">Teddy's Email: txd.cool@gmail.com</h2>
        </div>
    </div>
</div>

<p style="background-color: #36373C;width: 100%;height: 30px;position: absolute;bottom: 0px;color: #f8f8f8;text-align: center;padding-top: 15px;">© 2017~2018 &nbsp&nbsp 杭州九鼎网络</p>
</body>

<script>
    var loginInterval;

    //定时器，监测是否登录
    function checkLogin() {
        loginInterval = self.setInterval(function () {
                checkSession();
        }, 1000);
    }
    checkLogin();


    checkSession();
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use('element', function () {
        var element = layui.element;
        var form = layui.form;
        form.render();
        element.init();

        //轮播
        var carousel = layui.carousel;
        //建造实例
        carousel.render({
            elem: '#test1'
            , width: '100%' //设置容器宽度
            , arrow: 'always' //始终显示箭头
            //,anim: 'updown' //切换动画方式
        });
        //…
    });

    function checkSession() {
        $.ajax({
            url: "/v1.0/session",
            type: "GET",
            data: {},
            success: function (data) {

                if (isNotBlank(data)) {
                    $("#login").empty();
                    var user = getJointElement("<span>", '<img src= "',imageServerURL+"/"+getLocalObject("user").headPortrait,'" class="layui-nav-img">',data, "</span>");
                    $("#login").append(user);
                    var dl = '<dl class="layui-nav-child"> <!-- 二级菜单 -->\n' +
                        '            <dd><a href="/v1.0/setter" target="_blank">个人设置</a><a href="/v1.0/updateUser" target="_blank">信息修改</a><a href="/v1.0/removeSession">注销</a></dd>\n' +
                        '        </dl>';
                    $("#login").append(dl);
                    //已登录
                    window.clearInterval(loginInterval);
                }

            },
            error: function (e) {
                console.log(e)
            }

        });
    }

    //检查session权限
    function checkSessionJurisdiction() {
        var result = false;
        $.ajax({
            url: "/v1.0/session",
            type: "GET",
            async: false,
            data: {},
            success: function (data) {
                if (isNotBlank(data)) {
                    result = true;
                }
            },
            error: function (e) {
                console.log(e)
            }
        });
        return result;
    }


    function taobao_collect() {
        var result = checkSessionJurisdiction();
        if (!result) {
            layer.msg("请先登录,再进行操作");
            return;
        }

        $.ajax({
            url: serverURL + "/collector/saveCollectList_taobao",
            type: "POST",
            data: {
                url: $("#taobao_url").val(),
                userId: getLocalObject("user").id
            },
            success: function (data) {
                //layAsynMsg();
                layer.msg(data.meta);
            },
            error: function (e) {
                console.log(e)
            }

        });
    }

    function collect() {
        var result = checkSessionJurisdiction();
        if (!result) {
            layer.msg("请先登录,再进行操作");
            return;
        }
        $.ajax({
            url: serverURL + "/collector/saveCollectList_1688",
            type: "POST",
            data: {
                url: $("#url").val(),
                userId: getLocalObject("user").id
            },
            success: function (data) {
                layer.msg(data.meta);
            },
            error: function (e) {
                console.log(e)
            }

        });
    }

    function addField() {
        var index = layer.open({
            type: 2,
            title: '添加采集字段',
            //area: ['402px', '250px'], //['402px', '250px'],
            content: ['/v1.0/addField', 'no']//'http://layer.layui.com/test/settop.html'// './addAuthCode.html' //这里content是一个普通的String
        });
        layer.full(index);
    }

    function addCollectRule() {
        var index = layer.open({
            type: 2,
            title: '添加选择器规则',
            //area: ['402px', '250px'], //['402px', '250px'],
            content: ['/v1.0/addCollectRulePage', 'no']//'http://layer.layui.com/test/settop.html'// './addAuthCode.html' //这里content是一个普通的String
        });
        layer.full(index);
    }

</script>
</html>